package com.example.travel.service;


import com.example.travel.bean.IchBean;
import com.example.travel.mapper.IchMapper;
import com.example.travel.utils.DateFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IchService {

    @Autowired
    private IchMapper ichMapper;

    public List<IchBean> getAllIch() {
        return ichMapper.getAllIch();
    }


    public IchBean getIchById(int ichID) {
        return ichMapper.getIchById(ichID);
    }


    public boolean addIch(IchBean ich) {
        try {
            // 设置当前日期
            ich.setIchDate(DateFormatter.getDate());
            int result = ichMapper.addIch(ich);
            return result > 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public boolean updateIch(IchBean ich) {
        try {
            int result = ichMapper.updateIch(ich);
            return result > 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public boolean deleteIch(int ichID) {
        try {
            int result = ichMapper.deleteIch(ichID);
            return result > 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public List<IchBean> searchIchByName(String ichName) {
        return ichMapper.searchIchByName(ichName);
    }

    public List<IchBean> searchIchByLocation(String ichLocation) {
        return ichMapper.searchIchByLocation(ichLocation);
    }

    public List<IchBean> getIchListWithPagination(String searchKeyword, int offset, int pageSize) {
        return ichMapper.getIchListWithPagination(searchKeyword, offset, pageSize);
    }

    public int getIchCount(String searchKeyword) {
        return ichMapper.getIchCount(searchKeyword);
    }

}